import { Inject } from '@midwayjs/core';
import { CoolController, BaseController } from '@cool-midway/core';
import { OrderOrderEntity } from '../../entity/order';
import { OrderOrderService } from '../../service/order';
import { UserInfoEntity } from '../../../user/entity/info';
import { UserRelationEntity } from '../../../user/entity/user_relation';

/**
 * 订单信息
 */
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: OrderOrderEntity,
  service: OrderOrderService,
  pageQueryOp: {
    keyWordLikeFields: ['a.orderNo'],
    join: [
      {
        entity: UserInfoEntity,
        alias: 'b',
        condition: 'a.deviceBindUserId = b.id',
      },
      {
        entity: UserRelationEntity,
        alias: 'c',
        condition: 'a.deviceBindUserId = c.userId',
      }
    ],
    select: [
      'a.*',
      'b.phone AS deviceBindPhone',
      'b.nickName AS deviceBindNickName',
      "c.level1ParentId",
      "c.level2ParentId",
      "c.level3ParentId",
    ],
  },
})
export class AdminOrderOrderController extends BaseController {
  @Inject()
  orderOrderService: OrderOrderService;
}
